package com.sdkj.dspservice.modules.demand.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sdkj.dspservice.common.base.entity.DataEntity;
import com.sdkj.dspservice.common.utils.StringUtils;
import com.sdkj.dspservice.modules.sys.entity.User;
import lombok.Data;

import java.util.Date;

/**
 * 需求表Entity
 * @author tm
 */
@Data
@TableName(value = "demand_details")
public class DemandDetails extends DataEntity<DemandDetails> {

    /**
     * 操作类型：0：退回  1：提交（正常流转）  2：完成（已处理提交）  3：确定完成   4：关闭
     */
    public static final String MAKE_TYPE_REJECT = "0";
    public static final String MAKE_TYPE_FLOW = "1";
    public static final String MAKE_TYPE_PROCESSED = "2";
    public static final String MAKE_TYPE_FINISH = "3";
    public static final String MAKE_TYPE_ClOSE = "4";

    /**
     * 描述
     */
    private String description;
    /**
     * 本流程段排序
     */
    private Integer flowSort;
    /**
     * 本流程段花费时间，单位小时
     */
    private Integer spendTime;
    /**
     * 本流程段结束时间
     */
    private Date endDate;
    /**
     * 操作类型：0：驳回  1：提交（正常流转）  2：已完成（已处理提交）  3：完成需求   4：关闭需求
     */
    private String makeType;
    /**
     * 本流程段用户
     */
    private String userId;
    /**
     * 需求ID
     */
    private String demandId;
    /**
     * 需求状态
     */
    private String demandStatus;
    /**
     * 需求流程状态
     */
    private String demandFlowStatus;


    @TableField(exist = false)
    private Demand demand;
    @TableField(exist = false)
    private User user;

    public DemandDetails() {
        super();
    }

    public DemandDetails(String id) {
        super(id);
    }

    public DemandDetails(Demand demand) {
        super();
    }

    public String getMakeTypeName(){
        String result = null;
        if(StringUtils.isNotBlank(makeType)){
            switch (makeType){
                case MAKE_TYPE_REJECT:
                    result = "退回";
                    break;
                case MAKE_TYPE_FLOW:
                    result = "提交";
                    break;
                case MAKE_TYPE_PROCESSED:
                    result = "完成";
                    break;
                case MAKE_TYPE_FINISH:
                    result = "确定完成";
                    break;
                case MAKE_TYPE_ClOSE:
                    result = "关闭";
                    break;
                default:
                    result = null;
            }
        }
        return result;
    }

    public String getFlowStatusName() {
        String result = null;
        if (StringUtils.isNotBlank(demandFlowStatus)) {
            switch (demandFlowStatus) {
                case Demand.FLOW_STATUS_ClOSE:
                    result = "已关闭";
                    break;
                case Demand.FLOW_STATUS_SUBMITTED:
                    result = "已提交";
                    break;
                case Demand.FLOW_STATUS_VERIFY:
                    result = "待审核";
                    break;
                case Demand.FLOW_STATUS_DISTRIBUTION:
                    result = "待分派";
                    break;
                case Demand.FLOW_STATUS_PROCESS:
                    result = "待处理";
                    break;
                case Demand.FLOW_STATUS_WAIT_FINISH:
                    result = "待完成";
                    break;
                case Demand.FLOW_STATUS_FINISH:
                    result = "已完成";
                    break;
                case Demand.FLOW_STATUS_REJECT:
                    result = "已退回";
                    break;
                default:
                    result = null;
            }
        }
        return result;
    }

    /**
     * 把实体里的参数，放入查询中（只有关联查询需要这样，因为设置不了别名，只能手动插入）
     * @return
     */
    @Override
    public QueryWrapper<DemandDetails> makeQueryWrapper(QueryWrapper<DemandDetails> queryWrapper){
        if(StringUtils.isNotBlank(demandId)){
            queryWrapper.eq("a.demand_id", demandId);
        }
        super.makeQueryWrapper(queryWrapper);
        return queryWrapper;
    }

}
